function esRequest(url,method="GET",data=null){
    const username = 'elastic';
    const password = '123456';
    const credentials = `${username}:${password}`;
    const encodedCredentials = btoa(credentials);
    return new Promise((resolve, reject) => {

        // 发送 fetch 请求
        fetch(`http://47.93.32.193:9200/${url}`, {
            method,
            headers: {
                'Content-Type': 'application/json',
                'Authorization': `Basic ${encodedCredentials}`
            },
            body: data==null?null: JSON.stringify(data)
        })
            .then(response => {
                return response.json();
            })
            .then(data => {
                resolve(data);
            })
            .catch(error => {
                reject('Fetch error:' + error);
            });
    })
}
export default esRequest